SET(PROG_NAME wrap)
SET(SRCS wrap.c)

MACRO(DEFPROG LIBTYPE)
    MESSAGE(STATUS "Build: ${LIBTYPE}")

    INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/external/json/include/mjson-1.6)

    ADD_EXECUTABLE(${PROG_NAME}-${LIBTYPE}-static ${SRCS})

    TARGET_LINK_LIBRARIES(${PROG_NAME}-${LIBTYPE}-static
        ${PROJECT_SOURCE_DIR}/external/json/lib/${LIBTYPE}/libmjson.a
		#${PROJECT_SOURCE_DIR}/external/json/lib/${LIBTYPE}/libmjson.la
		#${PROJECT_SOURCE_DIR}/external/json/lib/${LIBTYPE}/libmjson.so
        pthread m rt stdc++
        )

    ADD_CUSTOM_COMMAND(TARGET ${PROG_NAME}-${LIBTYPE}-static POST_BUILD
        COMMAND ${CMAKE_STRIP} ${PROJECT_BINARY_DIR}/bin/${LIBTYPE}/${PROG_NAME}
        )

    IF(${LIBTYPE} STREQUAL glibc)
        SET_TARGET_PROPERTIES(${PROG_NAME}-${LIBTYPE}-static PROPERTIES
            OUTPUT_NAME "${PROG_NAME}"
	    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${LIBTYPE}
	    LINK_FLAGS "-Wl,-gc-sections"
	    )
    ELSE()
        SET_TARGET_PROPERTIES(${PROG_NAME}-${LIBTYPE}-static PROPERTIES
	    OUTPUT_NAME "${PROG_NAME}"
	    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${LIBTYPE}
	    LINK_FLAGS "-muclibc -Wl,-gc-sections"
	    COMPILE_FLAGS "-muclibc"
	    )
    ENDIF()

#    INSTALL(TARGETS ${PROG_NAME}-${LIBTYPE}
#        RUNTIME DESTINATION bin/${LIBTYPE}
#    )
ENDMACRO()

DEFPROG(glibc)
DEFPROG(uclibc)
